import { Editor } from "@tiptap/core";
import { DOMParser } from "@tiptap/pm/model";

export const parseHtml = (editor: Editor, html: string) => {
    function bodyElement(value: string): HTMLElement {
        return new window.DOMParser().parseFromString(`<body>${value}</body>`, 'text/html').body;
    }

    const parser = DOMParser.fromSchema(editor.schema);
    return parser.parse(bodyElement(html), {}).content;
}